🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / ble / src / commonMain / kotlin / org / meshtastic / core / ble / BleRetry.kt
Displaying Raw • Download
core/ble/src/commonMain/kotlin/org/meshtastic/core/ble/BleRetry.kt f07624be882e679affc02931dc75e8cb1594de18 (f07624be) Text, 2.00 KB
T8b949e/*
* Copyright (c) 2025-2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.ble
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.CancellationException
Tff7b72import T7ee787kotlinx.coroutines.delay
T8b949e/**
* Retries a BLE operation a specified number of times with a delay between attempts.
*
* @param count The number of attempts to make.
* @param delayMs The delay in milliseconds between attempts.
* @param tag A tag for logging.
* @param block The operation to perform.
* @return The result of the operation.
* @throws Exception if the operation fails after all attempts.
*/
Tff7b72suspend Tff7b72fun Tff7b72<Te6edf3TTff7b72> Td2a8ffretryBleOperationTb4b4b4(
Te6edf3countTb4b4b4: Tffa657Int Tff7b72= T79c0ff3Tb4b4b4,
Te6edf3delayMsTb4b4b4: Tffa657Long Tff7b72= T79c0ff5T79c0ff0T79c0ff0LTb4b4b4,
Te6edf3tagTb4b4b4: Tffa657String Tff7b72= Ta5d6ff"Ta5d6ffBLETa5d6ff"Tb4b4b4,
Te6edf3blockTb4b4b4: Te6edf3suspend Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Te6edf3TTb4b4b4,
Tb4b4b4)Tb4b4b4: Te6edf3T Tb4b4b4{
Tff7b72var Te6edf3currentAttempt Tff7b72= T79c0ff0
Tff7b72while Tb4b4b4(Tff7b72trueTb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Tff7b72return Te6edf3blockTb4b4b4(Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3CancellationExceptionTb4b4b4) Tb4b4b4{
Tff7b72throw Te6edf3e
Tb4b4b4} Tff7b72catch Tb4b4b4(Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4) Te6edf3eTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Te6edf3currentAttemptTff7b72+Tff7b72+
Tff7b72if Tb4b4b4(Te6edf3currentAttempt Tff7b72>Tff7b72= Te6edf3countTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ff[Tffd700$Te6edf3tagTa5d6ff] BLE operation failed after Tffd700$Te6edf3countTa5d6ff attempts, giving upTa5d6ff" Tb4b4b4}
Tff7b72throw Te6edf3e
Tb4b4b4}
Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{
Ta5d6ff"Ta5d6ff[Tffd700$Te6edf3tagTa5d6ff] BLE operation failed (attempt Tffd700$Te6edf3currentAttemptTa5d6ff/Tffd700$Te6edf3countTa5d6ff), Ta5d6ff" Tff7b72+ Ta5d6ff"Ta5d6ffretrying in Tffd700${Te6edf3delayMsTffd700}Ta5d6ffms...Ta5d6ff"
Tb4b4b4}
Te6edf3delayTb4b4b4(Te6edf3delayMsTb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.05s